<template>
    <div>
       <el-form :model="ndForm" :rules="rules" ref="ndForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="国防知识标题" prop="ndName" label-width="120px">
    <el-input v-model="ndForm.ndName" size="mini" style="width:300px"></el-input>
  </el-form-item>
  <el-form-item label="介绍" prop="ndDes">
    <el-input type="textarea" v-model="ndForm.ndDes"></el-input>
  </el-form-item>
  <el-form-item label="添加时间" prop="ndTime">
    <el-date-picker
      v-model="ndForm.ndTime"
      type="datetime"
      value-format="yyyy-MM-dd hh:mm:ss"
      placeholder="选择日期时间">
    </el-date-picker>
  </el-form-item>
  <el-form-item label="状态" prop="ndState">
    <el-switch v-model="ndForm.ndState"></el-switch>
  </el-form-item>
   <el-form-item>
    <el-button type="primary" @click="submitForm('ndForm')">立即创建</el-button>
    <el-button @click="resetForm('ndForm')">重置</el-button>
  </el-form-item>
</el-form>
    </div>
  </template>
  <script>
  import {addNationalDes} from '@/api'
  // 导入组件
 export default {
    name: 'addGoods',
    data() {
      return {
        ndForm: {
          ndName: '',
          ndDes: '',
           ndTime: '',
           ndState: false,
          },
        rules: {
            ndName: [
            { required: true, message: '请输入国防知识名称', trigger: 'blur' },
           
          ],
          ndDes: [
            { required: true, message: '请输入内容', trigger: 'change' }
          ]}
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            console.log(this.ndForm)
            let data ={
              title:this.ndForm.ndName,
              introduce:this.ndForm.ndDes,
              addtime:this.ndForm.ndTime,
              status:this.ndForm.ndState?1:0
            }
            addNationalDes(data).then(res=>{
              
              if(res.code == 200){
               this.$message.success('添加成功')
            }else{
              this.$message.error('添加失败，请重试！')
            }
            })
          } else {
          this.$message.error("请正确输入表单信息!")
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
  </script>
  <style >

  </style>
  